home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9568 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: confusion between putchar and printf
  5. Date: 11 Mar 1996 21:08:26 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4i24oa$9qv@sparcserver.lrz-muenchen.de>
  9. References: <4i1v2n$30o@news.azstarnet.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Howard Salmon <captarm@azstarnet.com> writes:
  13.  
  14. >K & R (section 1.5) states that "putchar(c) prints the contents of the 
  15. >integer variable c as a character, usually on the screen".
  16.  
  17. >Here's a small program that I wrote testing putchar.  Why doesn't it 
  18. >compile?
  19.  
  20. >#include <stdio.h>
  21. ># define A "hello world!"
  22.  
  23. >main()
  24. >{
  25. >    int c;
  26. >    c =  A;
  27.  
  28. Because there is no automatic conversion from "pointer to char" to "int"?
  29.  
  30. "hello world" is not a char, it is a string literal, and can be 
  31. treated like an array of char that is not const, but should not
  32. be modified.
  33.  
  34. >    putchar(A);
  35.  
  36. Try:
  37.  
  38.       for (c = 0; A[c]; c++)
  39.          putchar(A[c]);
  40.       putchar('\n');
  41.  
  42. or simply:
  43.  
  44.       puts(A);
  45.  
  46. And don't forget to return something from main(), otherwise you
  47. will return an undefined value to the operating system.
  48.  
  49. >}
  50.  
  51. Kurt
  52. --
  53. | Kurt Watzka                             Phone : +49-89-2180-6254
  54. | watzka@stat.uni-muenchen.de
  55. | ua302aa@sunmail.lrz-muenchen.de
  56.  
  57.